package com.lzx.applib.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;

/**
 * Created by Lzx on 16/12/07 0007.
 */
public class IntentUtil {
    public static final String TAG = "IntentUtil";

    public static void gotoMarket(Context context) {
        String id = context.getApplicationInfo().packageName;
        PackageManager packageManager = context.getApplicationContext().getPackageManager();
        Uri marketUri = Uri.parse("market://details?id=" + id);
        Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(marketUri);
        if (marketIntent.resolveActivity(packageManager) != null) {
            try {
                context.startActivity(marketIntent);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static void installAPK(Context context, String filename) {
        Intent intent_ins = new Intent(Intent.ACTION_VIEW);
        intent_ins.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent_ins.setDataAndType(Uri.parse("file://" + filename),"application/vnd.android.package-archive");
        context.getApplicationContext().startActivity(intent_ins);
    }

    public static void openWebUrl(Context context, String url) {
        Uri uri = Uri.parse(url);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        context.startActivity(intent);
    }
}
